package com.ymatou.iapi.godfreightmgr.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreightmgr.parameter.SetCollectionGoodsByAdminBean;
import com.ymatou.iapi.godfreightmgr.service.SetCollectionGoodsByAdminCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godfreight.DeliveryPatternConfig;
import com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper;
/**
*运营设置上门自提功能开关
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetCollectionGoodsByAdmin{
	private static SetCollectionGoodsByAdminBean setcollectiongoodsbyadminBean;
	private static SetCollectionGoodsByAdminCall setcollectiongoodsbyadminCall;
	com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper CollectionGoodsWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("运营设置上门自提功能开关");
	}

	@Before
	public void caseUp() {
		setcollectiongoodsbyadminBean=new SetCollectionGoodsByAdminBean();
		setcollectiongoodsbyadminCall=new SetCollectionGoodsByAdminCall();
		CollectionGoodsWapper=new CollectionGoodsWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setcollectiongoodsbyadminCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetCollectionGoodsByAdmin_001() {
		Logger.start(true,"运营设置上门自提功能开关成功-第一次打开");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			setcollectiongoodsbyadminBean.setEnableCollectionGoods(true);
			setcollectiongoodsbyadminBean.setSellerId(mchId_channl);
			setcollectiongoodsbyadminCall.setData(setcollectiongoodsbyadminBean);
			setcollectiongoodsbyadminCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbyadminCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsByAdmin_002() {
		Logger.start(true,"不输入sellerId失败");
		try {
			setcollectiongoodsbyadminBean.setEnableCollectionGoods(true);
			setcollectiongoodsbyadminCall.setData(setcollectiongoodsbyadminBean);
			setcollectiongoodsbyadminCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbyadminCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsByAdmin_003() {
		Logger.start(true,"不输入enableCollectionGoods失败");
		try {
			setcollectiongoodsbyadminBean.setSellerId(1);
			setcollectiongoodsbyadminCall.setData(setcollectiongoodsbyadminBean);
			setcollectiongoodsbyadminCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbyadminCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsByAdmin_004() {
		Logger.start(true,"运营设置上门自提功能开关成功-关闭");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			setcollectiongoodsbyadminBean.setEnableCollectionGoods(false);
			setcollectiongoodsbyadminBean.setSellerId(mchId_channl);
			setcollectiongoodsbyadminCall.setData(setcollectiongoodsbyadminBean);
			setcollectiongoodsbyadminCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbyadminCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(false, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsByAdmin_005() {
		Logger.start(true,"该店铺中有仅上门自提商品,不可关闭该功能");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId_channl, "",
                    true);
			addAgentProductBean.setExpressDelivery(false);
			addAgentProductBean.setCollectionGoods(true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			setcollectiongoodsbyadminBean.setEnableCollectionGoods(false);
			setcollectiongoodsbyadminBean.setSellerId(mchId_channl);
			setcollectiongoodsbyadminCall.setData(setcollectiongoodsbyadminBean);
			setcollectiongoodsbyadminCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbyadminCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsByAdmin_006() {
		Logger.start(true,"运营设置上门自提功能开关成功-反复开关");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
			setcollectiongoodsbyadminBean.setEnableCollectionGoods(true);
			setcollectiongoodsbyadminBean.setSellerId(mchId_channl);
			setcollectiongoodsbyadminCall.setData(setcollectiongoodsbyadminBean);
			setcollectiongoodsbyadminCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbyadminCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsByAdmin_007() {
		Logger.start(true,"运营设置上门自提功能开关成功-有商品设置过自提-关闭");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId_channl, "",
                    true);
			addAgentProductBean.setExpressDelivery(true);
			addAgentProductBean.setCollectionGoods(true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			
			setcollectiongoodsbyadminBean.setEnableCollectionGoods(false);
			setcollectiongoodsbyadminBean.setSellerId(mchId_channl);
			setcollectiongoodsbyadminCall.setData(setcollectiongoodsbyadminBean);
			setcollectiongoodsbyadminCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbyadminCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(false, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}